<?php
namespace app\api\controller;

use \think\Controller;
use \think\Db;
require '/data/wwwroot/mww5.xuanwumobile.com/extend/qiniu/autoload.php';
use Qiniu\Auth;
class My extends Base
{

    /**
     * @return string
     * get七牛token
     */
    public function getQiniuToken(){
        header("Access-Control-Allow-Origin:*");
        $accessKey = 'vZhvvyqjDAv6BNfzlFzvU4UwWO4q3LgjdSSxfVHH';
        $secretKey = 'r2rWziRvnu-3sed9iXY1ke92D6rKEQUNH85GOyfg';
        $auth = new Auth($accessKey, $secretKey);
        $bucket = 'hongji';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        return json_encode(['status'=>200,'msg'=>$token]);
    }
    /**
     * 修改头像或者昵称
     * name,avatar
     */
    public function myInfo()
    {
		extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $data = Db::table('up_u_user')
            ->where('user_id', $user_id)
            ->find();
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 修改头像或者昵称
     * name,avatar
     */
    public function index()
    {
		extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $update = array();
        if(isset($name)) {
            $update['user_username'] = $name;
        }
        if(isset($avatar)){
            $update['user_image'] = $avatar;
        }
        Db::table('up_u_user')
            ->where('user_id', $user_id)
            ->update($update);
        return json_encode(['status'=>200,'msg'=>'修改成功']);
    }
    /**
     * 意见反馈类型
     * $content,$phone,$type
     */
    public function feedbackTypes(){
		extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $res = Db::table('up_feedback_cate')
            ->field('cate_id,cate_name')
            ->select();
        return json_encode(['status'=>200,'msg'=>$res]);
    }
    /**
     * 意见反馈
     * $content,$phone,$type
     */
    public function feedback(){
		extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $data = array();
        $data['f_user_id'] = $user_id;
        $data['f_type'] = trim($type,',');
        $data['f_content'] = $content;
        $data['f_phone'] = $phone;
        $data['f_time'] = date('Y-m-d H:i:s');
        $res = Db::table('up_feedback')->insert($data);
        if($res){
            return json_encode(['status'=>200,'msg'=>'提交成功']);
        }else{
            return json_encode(['status'=>0,'msg'=>'提交失败']);
        }
    }
    /**
     * 关于我们
     *
     */
    public function aboutus(){
        header("Access-Control-Allow-Origin:*");
        $data = Db::table('up_about')->where('a_id',1)->find();
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 协议：通用
     *
     */
    public function xieyi(){
        header("Access-Control-Allow-Origin:*");
        $data = Db::table('up_about')->where('a_id',4)->find();
        return json_encode(['status'=>200,'msg'=>$data]);
    }
//    /**
//     * 消息通知
//     *
//     */
//    public function notice(){
//		extract(input());
//        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
//        if($auth == false){
//            $returnData['status'] = 301;
//            $returnData['msg'] = "Token失效！请重新登录！";
//            return json_encode($returnData);
//        }
//        $data = Db::table('up_notice')
//            ->select();
//        return json_encode(['status'=>200,'msg'=>$data]);
//    }


}